<?php
require_once '../sub/init.php';
define('ZEAI2',dirname(__FILE__).DIRECTORY_SEPARATOR);
require_once 'chkUadm.php';
$crm_left_top_menu = dataIO($_ADM['crm_left_top_menu'.$session_uid],'out');
$crm_left_top_menu = explode(',',$crm_left_top_menu );?>
<div class="lmainbox">
<div class="logo">红娘CRM<font>v6.1</font></div>
<div class="L on">
    <dt><i class="ico">&#xe65e;</i>工作台</dt>
    <dd>
        <a url="crm_welcome.php" class="ed">● 待办首页</a>
        <div id="diydd"><?php
        if (count($crm_left_top_menu) >= 1 && is_array($crm_left_top_menu) && !empty($_ADM['crm_left_top_menu'.$session_uid])){
            foreach ($crm_left_top_menu as $V) {
                $VARR = explode('|WWW.A9A.CN|',$V);$url=$VARR[0];$title=$VARR[1];
                echo '<a url="'.$url.'">'.$title.'</a>';
            }
        }?></div>
        <?php if(CRMQX('crm_left_top_menu')){?>
        <a url="left_diy.php?t=crm"><i class="ico">&#xe6a7;</i> 自定义<font class="newdian"></font></a>
        <?php }?>
    </dd>
</div>

<?php if ($session_crmkind!='ht' && $session_crmkind!='cw' && $session_crmkind!='ht,cw' || CRM_ADM){?>
<div class="L<?php echo (!CRM_ADM)?' on':'';?>">
    <dt><i class="ico">&#xe617;</i>客户管理</dt>
    <dd>
        <?php if(CRMQX('claim')){?><a url="crm_claim_public.php">● 公海资源<font class="newdian"></font></a><?php }?>
        <?php if(CRMQX('crm_user')){?><a url="crm_user.php<?php echo (!strstr($session_crmkind,'adm') && !CRM_ADM)?'?ifmy=1':'';?>" title="只显示已认领用户">● 客户管理</a><?php }?>
        <?php if(CRMQX('crm_user_select')){?><a url="u_select.php?k=crm&uflag=1_2">● 客户查询</a><?php }?>
        <?php if(CRMQX('crm_u_add')){?><a url="u_add.php">● 客户录入</a><?php }?>
        <?php if (strstr($session_crmkind,'sq') || CRM_ADM){?><a url="crm_sq.php?t=1<?php echo (!strstr($session_crmkind,'adm') && !CRM_ADM)?'&ifmy=1':'';?>" title="认领后未签约或没交钱的用户">● 售前客户</a><?php }?>
        <?php if (strstr($session_crmkind,'sh') || CRM_ADM){?><a url="crm_sh.php?t=3<?php echo (!strstr($session_crmkind,'adm') && !CRM_ADM)?'&ifmy=1':'';?>" title="认领后（已签约或已交钱升级了客户等级）的用户">● 售后客户</a><?php }?>
        <hr />
        <?php if(CRMQX('u_qianxian')){?><a url="u_qianxian.php?ifonline=1&qxflag=1">● 线上牵线</a><?php }?>
        <?php if(CRMQX('u_jb_list')){?><a url="u_jb_list.php?sort=myinfobfb1">● 资料审核</a><?php }?>
        <?php if(CRMQX('claim_adm')){?><a url="crm_claim.php">● 认领管理</a><?php }?>
        <?php if(CRMQX('tip_list') || CRMQX('chat_list') || CRMQX('view_list') || CRMQX('gz_list') || CRMQX('hh_list') || CRMQX('u_bbs') || CRMQX('u_endtime') ){?><a url="u_endtime.php">● 用户轨迹<font class="newdian"></font></a><?php }?>
    </dd>
</div>
<?php if (CRM_ADM || CRMQX('crm_bbs_list') || CRMQX('u_qianxian') || CRMQX('crm_match_list') ){?>
<div class="L on">
    <dt><i class="ico">&#xe613;</i>线下服务</dt>
    <dd>
	<?php if(CRMQX('crm_bbs_list')){?><a url="crm_user_bbs.php<?php echo (!strstr($session_crmkind,'adm') && !CRM_ADM)?'?ifmy=1':'';?>">● 跟进列表</a><?php }?>
    <?php if(CRMQX('u_qianxian')){?><a url="u_qianxian.php<?php echo (!strstr($session_crmkind,'adm') && !CRM_ADM)?'?ifmy=1':'';?>">● 牵线列表</a><?php }?>
    <?php if(CRMQX('crm_match_list')){?><a url="crm_user_meet.php<?php echo (!strstr($session_crmkind,'adm') && !CRM_ADM)?'?ifmy=1':'';?>">● 约见列表</a><?php }?>
    <?php if(CRMQX('form')){?><a url="form.php">● 表单采集</a><?php }?>
    </dd>
</div>
<?php }}?>

<?php if (CRMQX('crm_talk_gh') || CRMQX('crm_talk_gj') || CRMQX('crm_talk_tj')){?>
<div class="L">
    <dt><i class="ico">&#xe68b;</i>外呼跟进</dt>
    <dd>
    <?php if(CRMQX('crm_talk_gh')){ ?><a url="crm_talk_gh.php">● 外呼客户公海</a><?php }?>
    <?php if(CRMQX('crm_talk_gj')){ ?><a url="crm_talk_gj.php">● 外呼客户跟进</a><?php }?>
    <?php if(CRMQX('crm_talk_tj')){ ?><a url="crm_talk_tj.php">● 外呼统计报表</a><?php }?>
    </dd>
</div>
<?php }?>


<?php if (CRM_ADM || strstr($session_crmkind,'ht') || strstr($session_crmkind,'cw') || CRMQX('crm_pay_analyse') || CRMQX('analyse_month') || CRMQX('analyse_u') || CRMQX('analyse_hn_month') ){?>
<div class="L">
    <dt><i class="ico">&#xe626;</i>数据管理</dt>
    <dd>
        <?php if (strstr($session_crmkind,'ht') || CRM_ADM){?><a url="crm_ht.php?t=htflagall">● 合同管理</a><?php }?>
    	<?php if (strstr($session_crmkind,'cw') || CRM_ADM){?><a url="crm_ht.php?t=payflagall">● 财务审核</a><?php }?>
    	<?php if(CRMQX('crm_pay_analyse')){?><a url="crm_pay_analyse.php">● 财务统计</a><?php }?>
        <?php if(CRMQX('analyse_month')){?><a url="analyse_month.php?t=1">● 数据月报</a><?php }?>
        <?php if(CRMQX('analyse_u')){?>
            <a url="analyse_u.php?t=1">● 客户分析</a>
            <a url="analyse_u.php?t=2">● 资料分析</a>
		<?php }?>
        <?php if(CRMQX('analyse_hn_month')){?><a url="analyse_hn_month.php">● 红娘报表</a><?php }?>
    </dd>
</div>
<?php }?>

<?php if (CRM_ADM || CRMQX('crm_hn') || CRMQX('crm_hn_bbs') || CRMQX('crm_news') || CRMQX('log') ){?>
<div class="L">
    <dt><i class="ico">&#xe902;</i>系统管理</dt>
    <dd>
    	<?php if(CRM_ADM){?>
            <a url="crm_agent.php">● 门店管理</a>
            <a url="crm_role.php">● 红娘角色</a>
		<?php }?>
        <?php if(CRMQX('crm_hn')){?><a url="crm_hn.php">● 红娘管理</a><?php }?>
        <?php if(CRMQX('crm_hn_bbs')){?><a url="crm_hn_bbs.php">● 红娘评价</a><?php }?>
        <hr />
        <?php if(CRMQX('crm_news')){?><a url="crm_news.php">● 通知公告</a><?php }?>
        <?php if(CRM_ADM){?>
        	<a url="crm_udata3.php">● 资料属性</a>
        	<a url="crm_set.php">● CRM设置</a>
		<?php }?>
        <?php if(CRMQX('log')){?><a url="log.php">● 操作日志</a><?php }?>
    </dd>
</div>
<?php }?>
<div class="blank"></div>
</div>
<script src="js/left.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<?php
/********坠海*******/
if($_CRM['sea_hn_day']>0){// && $session_uid==25
	$seatime1 = $_CRM['sea_hn_day']*86400;
	$SQL  = " (flag=1 OR flag=-2) AND kind<>4 AND admid>0 AND hnid>0 AND crm_ugrade=0 AND (".ADDTIME." - seatime) > $seatime1";
	$rt2=$db->query("SELECT id,nickname,truename,hnid FROM ".__TBL_USER__." WHERE ".$SQL);
	$total2 = $db->num_rows($rt2);
	if ($total2 > 0) {
		for($i2=1;$i2<=$total2;$i2++) {
			$rows2 = $db->fetch_array($rt2,'name');
			if(!$rows2) break;
			$uid      = $rows2['id'];
			$nickname = trimhtml(dataIO($rows2['nickname'],'out'));
			$truename = trimhtml(dataIO($rows2['truename'],'out'));
			$truename = (!empty($truename))?'（姓名:'.$truename.'）':'';
			$hnid     = intval($rows2['hnid']);
			//
			$row = $db->ROW(__TBL_ADMIN__,"username,agentid,agenttitle","id=".$hnid,"name");
			if($row){
				$session_uid        = $hnid;
				$session_uname      = trimhtml(dataIO($row['username'],'out'));
				$session_kind       = 'crm';
				$session_agentid    = $row['agentid'];
				$session_agenttitle = $row['agenttitle'];
				$db->query("UPDATE ".__TBL_USER__." SET hnid=0,hnname='',hntime=0 WHERE id=".$uid);
				AddLog('【售前'.$_CRM['sea_hn_day'].'天自动坠海】->客户【'.$nickname.$truename.'（uid:'.$uid.'）】');
			}
		}
	}
}
if($_CRM['sea_hn2_day']>0){//
	$seatime1 = $_CRM['sea_hn2_day']*86400;
	$SQL  = " (flag=1 OR flag=-2) AND kind<>4 AND admid>0 AND hnid2>0 AND crm_ugrade>0 AND crm_flag<>3 AND (".ADDTIME." - seatime) > $seatime1 ";
	$rt2=$db->query("SELECT id,nickname,truename,hnid2 FROM ".__TBL_USER__." WHERE ".$SQL);
	$total2 = $db->num_rows($rt2);
	if ($total2 > 0) {
		for($i2=1;$i2<=$total2;$i2++) {
			$rows2 = $db->fetch_array($rt2,'name');
			if(!$rows2) break;
			$uid      = $rows2['id'];
			$nickname = trimhtml(dataIO($rows2['nickname'],'out'));
			$truename = trimhtml(dataIO($rows2['truename'],'out'));
			$truename = (!empty($truename))?'（姓名:'.$truename.'）':'';
			$hnid2     = intval($rows2['hnid2']);
			//
			$row = $db->ROW(__TBL_ADMIN__,"username,agentid,agenttitle","id=".$hnid2,"name");
			$session_uid        = $hnid2;
			$session_uname      = trimhtml(dataIO($row['username'],'out'));
			$session_kind       = 'crm';
			$session_agentid    = $row['agentid'];
			$session_agenttitle = $row['agenttitle'];
			//
			$db->query("UPDATE ".__TBL_USER__." SET hnid2=0,hnname2='',hntime2=0 WHERE id=".$uid);
			AddLog('【售后'.$_CRM['sea_hn2_day'].'天自动坠海】->客户【'.$nickname.$truename.'（uid:'.$uid.'）】');
		}
	}
}
?>
